/**********************************************************************
*
*   Copyright(C) 2021
*   FileName:
*   Version : V0.0.1
*   Date    : 2024-04-20
*   Author  : Song.YuLong@chipsbank
*   Description:
*
*   Others:
*
*   Function List:
*   History      :
*
***********************************************************************/
#include "app_config.h"
#include "stdio.h"
#include "stdlib.h"
#include "debug.h"

#include "ff.h"

#include "drv_spi_norflash.h"
#include "app_common.h"
#include "lcd_draw_base.h"
#include "lcd_draw_font.h"

#if TCFG_DRV_LCD_SPI_SUPPORT

#if D_DRAW_SCROLL_ENABLE
enum {
    E_DRAW_SCROLL_STOP=0,   /* 停止滚动 */
    E_DRAW_SCROLL_PLAY,     /* 开始滚动 */
    E_DRAW_SCROLL_PAUSE,    /* 暂停滚动 */
};

struct lcd_draw_t {
    uint8_t scroll_fb[128][8*6];   /* 垂直滚动FB */
    u8 status;
    u8 speed;
    u8 x0;
    u8 y0;
    u32 time;
};

static struct lcd_draw_t draw;
#define __this (draw)

/**
 * @brief   
*/
void lcd_draw_scroll_clear(void)
{
    memset(__this.scroll_fb, 0, sizeof(__this.scroll_fb));
}

void lcd_draw_scroll_str(char *str, int x, int y, u8 font_size, u8 wordspace, u8 align, uint8_t draw_inverse, u8 draw_mode)
{

}
#endif


/**
 * @brief   获取字符串占用宽度
 * @param   str：字符穿
 * @param   font_size: 字体大小
 * @param   wordspace: 字符间隔
 * @return  占用像素宽度
*/
int lcd_draw_string_width_get(char* str, u8 font_size, u8 wordspace)
{
    int pixels=0;
    int w=0;
    uint8_t*_code = (uint8_t*)str;

    if (E_FONT_S08X16 == font_size) {
        w = D_FONT_W_8;
    } else if (E_FONT_S12X12 == font_size) {
        w = D_FONT_W_12;
    } else if (E_FONT_S16X16 == font_size) {
        w = D_FONT_W_16;
    } else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
    } else if (E_FONT_S24X24 == font_size) {
        w = D_FONT_W_24;
    } else if (E_FONT_S32X32 == font_size) {
        w = D_FONT_W_32;
    }

    while((*_code) != '\0')
    {
        u8 flag = (u8)*_code;
        if (flag <= 0x7F) {
            /* ASCII    单字节 UTF8-1  0x00-0x7F */
            pixels += w + wordspace; 
            _code += 1;
        } else if ((flag>=0xC2)&&(flag<=0xDF)) {
            /* 汉语拼音  双字节 UTF8-2  0xC2-0xDF 0x80-0xBF */
            pixels += w + wordspace; 
            _code += 2; 
        } else if ((flag>=0xE0)&&(flag<=0xEF)) {
            /* 汉字     三字节 UTF8-3  */
            pixels += w + wordspace; 
            _code += 3;
        } else if ((flag>=0xF0)&&(flag<=0xF4)) {
            /*   四字节 UTF8-4  */
            log_e("unknow utf-8");
            _code += 4;
        }
    }

    return pixels;
}

#if TCFG_FONT_NORFLASH_DATA_ENABLE

#if TCFG_FONT_LIBRARY_TYPE == 2     // GBK 字库编码
static uint16_t code unicode2gbk [] = {
    // UNICODE  GBK(OEM936)
    0x00A4, 0xA1E8,
    0x00A7, 0xA1EC,
    0x00A8, 0xA1A7,
    0x00B0, 0xA1E3,
    0x00B1, 0xA1C0,
    0x00B7, 0xA1A4,
    0x00D7, 0xA1C1,
    0x00E0, 0xA8A4,
    0x00E1, 0xA8A2,
    0x00E8, 0xA8A8,
    0x00E9, 0xA8A6,
    0x00EA, 0xA8BA,
    0x00EC, 0xA8AC,
    0x00ED, 0xA8AA,
    0x00F2, 0xA8B0,
    0x00F3, 0xA8AE,
    0x00F7, 0xA1C2,
    0x00F9, 0xA8B4,
    0x00FA, 0xA8B2,
    0x00FC, 0xA8B9,
    0x0101, 0xA8A1,
    0x0113, 0xA8A5,
    0x011B, 0xA8A7,
    0x012B, 0xA8A9,
    0x0144, 0xA8BD,
    0x0148, 0xA8BE,
    0x014D, 0xA8AD,
    0x016B, 0xA8B1,
    0x01CE, 0xA8A3,
    0x01D0, 0xA8AB,
    0x01D2, 0xA8AF,
    0x01D4, 0xA8B3,
    0x01D6, 0xA8B5,
    0x01D8, 0xA8B6,
    0x01DA, 0xA8B7,
    0x01DC, 0xA8B8,
    0x0251, 0xA8BB,
    0x0261, 0xA8C0,
    0x02C7, 0xA1A6,
    0x02C9, 0xA1A5,
    0x02CA, 0xA840,
    0x02CB, 0xA841,
    0x02D9, 0xA842,
    0x0391, 0xA6A1,
    0x0392, 0xA6A2,
    0x0393, 0xA6A3,
    0x0394, 0xA6A4,
    0x0395, 0xA6A5,
    0x0396, 0xA6A6,
    0x0397, 0xA6A7,
    0x0398, 0xA6A8,
    0x0399, 0xA6A9,
    0x039A, 0xA6AA,
    0x039B, 0xA6AB,
    0x039C, 0xA6AC,
    0x039D, 0xA6AD,
    0x039E, 0xA6AE,
    0x039F, 0xA6AF,
    0x03A0, 0xA6B0,
    0x03A1, 0xA6B1,
    0x03A3, 0xA6B2,
    0x03A4, 0xA6B3,
    0x03A5, 0xA6B4,
    0x03A6, 0xA6B5,
    0x03A7, 0xA6B6,
    0x03A8, 0xA6B7,
    0x03A9, 0xA6B8,
    0x03B1, 0xA6C1,
    0x03B2, 0xA6C2,
    0x03B3, 0xA6C3,
    0x03B4, 0xA6C4,
    0x03B5, 0xA6C5,
    0x03B6, 0xA6C6,
    0x03B7, 0xA6C7,
    0x03B8, 0xA6C8,
    0x03B9, 0xA6C9,
    0x03BA, 0xA6CA,
    0x03BB, 0xA6CB,
    0x03BC, 0xA6CC,
    0x03BD, 0xA6CD,
    0x03BE, 0xA6CE,
    0x03BF, 0xA6CF,
    0x03C0, 0xA6D0,
    0x03C1, 0xA6D1,
    0x03C3, 0xA6D2,
    0x03C4, 0xA6D3,
    0x03C5, 0xA6D4,
    0x03C6, 0xA6D5,
    0x03C7, 0xA6D6,
    0x03C8, 0xA6D7,
    0x03C9, 0xA6D8,
    0x0401, 0xA7A7,
    0x0410, 0xA7A1,
    0x0411, 0xA7A2,
    0x0412, 0xA7A3,
    0x0413, 0xA7A4,
    0x0414, 0xA7A5,
    0x0415, 0xA7A6,
    0x0416, 0xA7A8,
    0x0417, 0xA7A9,
    0x0418, 0xA7AA,
    0x0419, 0xA7AB,
    0x041A, 0xA7AC,
    0x041B, 0xA7AD,
    0x041C, 0xA7AE,
    0x041D, 0xA7AF,
    0x041E, 0xA7B0,
    0x041F, 0xA7B1,
    0x0420, 0xA7B2,
    0x0421, 0xA7B3,
    0x0422, 0xA7B4,
    0x0423, 0xA7B5,
    0x0424, 0xA7B6,
    0x0425, 0xA7B7,
    0x0426, 0xA7B8,
    0x0427, 0xA7B9,
    0x0428, 0xA7BA,
    0x0429, 0xA7BB,
    0x042A, 0xA7BC,
    0x042B, 0xA7BD,
    0x042C, 0xA7BE,
    0x042D, 0xA7BF,
    0x042E, 0xA7C0,
    0x042F, 0xA7C1,
    0x0430, 0xA7D1,
    0x0431, 0xA7D2,
    0x0432, 0xA7D3,
    0x0433, 0xA7D4,
    0x0434, 0xA7D5,
    0x0435, 0xA7D6,
    0x0436, 0xA7D8,
    0x0437, 0xA7D9,
    0x0438, 0xA7DA,
    0x0439, 0xA7DB,
    0x043A, 0xA7DC,
    0x043B, 0xA7DD,
    0x043C, 0xA7DE,
    0x043D, 0xA7DF,
    0x043E, 0xA7E0,
    0x043F, 0xA7E1,
    0x0440, 0xA7E2,
    0x0441, 0xA7E3,
    0x0442, 0xA7E4,
    0x0443, 0xA7E5,
    0x0444, 0xA7E6,
    0x0445, 0xA7E7,
    0x0446, 0xA7E8,
    0x0447, 0xA7E9,
    0x0448, 0xA7EA,
    0x0449, 0xA7EB,
    0x044A, 0xA7EC,
    0x044B, 0xA7ED,
    0x044C, 0xA7EE,
    0x044D, 0xA7EF,
    0x044E, 0xA7F0,
    0x044F, 0xA7F1,
    0x0451, 0xA7D7,
    0x2010, 0xA95C,
    0x2013, 0xA843,
    0x2014, 0xA1AA,
    0x2015, 0xA844,
    0x2016, 0xA1AC,
    0x2018, 0xA1AE,
    0x2019, 0xA1AF,
    0x201C, 0xA1B0,
    0x201D, 0xA1B1,
    0x2025, 0xA845,
    0x2026, 0xA1AD,
    0x2030, 0xA1EB,
    0x2032, 0xA1E4,
    0x2033, 0xA1E5,
    0x2035, 0xA846,
    0x203B, 0xA1F9,
    0x20AC, 0x0080,
    0x2103, 0xA1E6,
    0x2105, 0xA847,
    0x2109, 0xA848,
    0x2116, 0xA1ED,
    0x2121, 0xA959,
    0x2160, 0xA2F1,
    0x2161, 0xA2F2,
    0x2162, 0xA2F3,
    0x2163, 0xA2F4,
    0x2164, 0xA2F5,
    0x2165, 0xA2F6,
    0x2166, 0xA2F7,
    0x2167, 0xA2F8,
    0x2168, 0xA2F9,
    0x2169, 0xA2FA,
    0x216A, 0xA2FB,
    0x216B, 0xA2FC,
    0x2170, 0xA2A1,
    0x2171, 0xA2A2,
    0x2172, 0xA2A3,
    0x2173, 0xA2A4,
    0x2174, 0xA2A5,
    0x2175, 0xA2A6,
    0x2176, 0xA2A7,
    0x2177, 0xA2A8,
    0x2178, 0xA2A9,
    0x2179, 0xA2AA,
    0x2190, 0xA1FB,
    0x2191, 0xA1FC,
    0x2192, 0xA1FA,
    0x2193, 0xA1FD,
    0x2196, 0xA849,
    0x2197, 0xA84A,
    0x2198, 0xA84B,
    0x2199, 0xA84C,
    0x2208, 0xA1CA,
    0x220F, 0xA1C7,
    0x2211, 0xA1C6,
    0x2215, 0xA84D,
    0x221A, 0xA1CC,
    0x221D, 0xA1D8,
    0x221E, 0xA1DE,
    0x221F, 0xA84E,
    0x2220, 0xA1CF,
    0x2223, 0xA84F,
    0x2225, 0xA1CE,
    0x2227, 0xA1C4,
    0x2228, 0xA1C5,
    0x2229, 0xA1C9,
    0x222A, 0xA1C8,
    0x222B, 0xA1D2,
    0x222E, 0xA1D3,
    0x2234, 0xA1E0,
    0x2235, 0xA1DF,
    0x2236, 0xA1C3,
    0x2237, 0xA1CB,
    0x223D, 0xA1D7,
    0x2248, 0xA1D6,
    0x224C, 0xA1D5,
    0x2252, 0xA850,
    0x2260, 0xA1D9,
    0x2261, 0xA1D4,
    0x2264, 0xA1DC,
    0x2265, 0xA1DD,
    0x2266, 0xA851,
    0x2267, 0xA852,
    0x226E, 0xA1DA,
    0x226F, 0xA1DB,
    0x2295, 0xA892,
    0x2299, 0xA1D1,
    0x22A5, 0xA1CD,
    0x22BF, 0xA853,
    0x2312, 0xA1D0,
    0x2460, 0xA2D9,
    0x2461, 0xA2DA,
    0x2462, 0xA2DB,
    0x2463, 0xA2DC,
    0x2464, 0xA2DD,
    0x2465, 0xA2DE,
    0x2466, 0xA2DF,
    0x2467, 0xA2E0,
    0x2468, 0xA2E1,
    0x2469, 0xA2E2,
    0x2474, 0xA2C5,
    0x2475, 0xA2C6,
    0x2476, 0xA2C7,
    0x2477, 0xA2C8,
    0x2478, 0xA2C9,
    0x2479, 0xA2CA,
    0x247A, 0xA2CB,
    0x247B, 0xA2CC,
    0x247C, 0xA2CD,
    0x247D, 0xA2CE,
    0x247E, 0xA2CF,
    0x247F, 0xA2D0,
    0x2480, 0xA2D1,
    0x2481, 0xA2D2,
    0x2482, 0xA2D3,
    0x2483, 0xA2D4,
    0x2484, 0xA2D5,
    0x2485, 0xA2D6,
    0x2486, 0xA2D7,
    0x2487, 0xA2D8,
    0x2488, 0xA2B1,
    0x2489, 0xA2B2,
    0x248A, 0xA2B3,
    0x248B, 0xA2B4,
    0x248C, 0xA2B5,
    0x248D, 0xA2B6,
    0x248E, 0xA2B7,
    0x248F, 0xA2B8,
    0x2490, 0xA2B9,
    0x2491, 0xA2BA,
    0x2492, 0xA2BB,
    0x2493, 0xA2BC,
    0x2494, 0xA2BD,
    0x2495, 0xA2BE,
    0x2496, 0xA2BF,
    0x2497, 0xA2C0,
    0x2498, 0xA2C1,
    0x2499, 0xA2C2,
    0x249A, 0xA2C3,
    0x249B, 0xA2C4,
    0x2500, 0xA9A4,
    0x2501, 0xA9A5,
    0x2502, 0xA9A6,
    0x2503, 0xA9A7,
    0x2504, 0xA9A8,
    0x2505, 0xA9A9,
    0x2506, 0xA9AA,
    0x2507, 0xA9AB,
    0x2508, 0xA9AC,
    0x2509, 0xA9AD,
    0x250A, 0xA9AE,
    0x250B, 0xA9AF,
    0x250C, 0xA9B0,
    0x250D, 0xA9B1,
    0x250E, 0xA9B2,
    0x250F, 0xA9B3,
    0x2510, 0xA9B4,
    0x2511, 0xA9B5,
    0x2512, 0xA9B6,
    0x2513, 0xA9B7,
    0x2514, 0xA9B8,
    0x2515, 0xA9B9,
    0x2516, 0xA9BA,
    0x2517, 0xA9BB,
    0x2518, 0xA9BC,
    0x2519, 0xA9BD,
    0x251A, 0xA9BE,
    0x251B, 0xA9BF,
    0x251C, 0xA9C0,
    0x251D, 0xA9C1,
    0x251E, 0xA9C2,
    0x251F, 0xA9C3,
    0x2520, 0xA9C4,
    0x2521, 0xA9C5,
    0x2522, 0xA9C6,
    0x2523, 0xA9C7,
    0x2524, 0xA9C8,
    0x2525, 0xA9C9,
    0x2526, 0xA9CA,
    0x2527, 0xA9CB,
    0x2528, 0xA9CC,
    0x2529, 0xA9CD,
    0x252A, 0xA9CE,
    0x252B, 0xA9CF,
    0x252C, 0xA9D0,
    0x252D, 0xA9D1,
    0x252E, 0xA9D2,
    0x252F, 0xA9D3,
    0x2530, 0xA9D4,
    0x2531, 0xA9D5,
    0x2532, 0xA9D6,
    0x2533, 0xA9D7,
    0x2534, 0xA9D8,
    0x2535, 0xA9D9,
    0x2536, 0xA9DA,
    0x2537, 0xA9DB,
    0x2538, 0xA9DC,
    0x2539, 0xA9DD,
    0x253A, 0xA9DE,
    0x253B, 0xA9DF,
    0x253C, 0xA9E0,
    0x253D, 0xA9E1,
    0x253E, 0xA9E2,
    0x253F, 0xA9E3,
    0x2540, 0xA9E4,
    0x2541, 0xA9E5,
    0x2542, 0xA9E6,
    0x2543, 0xA9E7,
    0x2544, 0xA9E8,
    0x2545, 0xA9E9,
    0x2546, 0xA9EA,
    0x2547, 0xA9EB,
    0x2548, 0xA9EC,
    0x2549, 0xA9ED,
    0x254A, 0xA9EE,
    0x254B, 0xA9EF,
    0x2550, 0xA854,
    0x2551, 0xA855,
    0x2552, 0xA856,
    0x2553, 0xA857,
    0x2554, 0xA858,
    0x2555, 0xA859,
    0x2556, 0xA85A,
    0x2557, 0xA85B,
    0x2558, 0xA85C,
    0x2559, 0xA85D,
    0x255A, 0xA85E,
    0x255B, 0xA85F,
    0x255C, 0xA860,
    0x255D, 0xA861,
    0x255E, 0xA862,
    0x255F, 0xA863,
    0x2560, 0xA864,
    0x2561, 0xA865,
    0x2562, 0xA866,
    0x2563, 0xA867,
    0x2564, 0xA868,
    0x2565, 0xA869,
    0x2566, 0xA86A,
    0x2567, 0xA86B,
    0x2568, 0xA86C,
    0x2569, 0xA86D,
    0x256A, 0xA86E,
    0x256B, 0xA86F,
    0x256C, 0xA870,
    0x256D, 0xA871,
    0x256E, 0xA872,
    0x256F, 0xA873,
    0x2570, 0xA874,
    0x2571, 0xA875,
    0x2572, 0xA876,
    0x2573, 0xA877,
    0x2581, 0xA878,
    0x2582, 0xA879,
    0x2583, 0xA87A,
    0x2584, 0xA87B,
    0x2585, 0xA87C,
    0x2586, 0xA87D,
    0x2587, 0xA87E,
    0x2588, 0xA880,
    0x2589, 0xA881,
    0x258A, 0xA882,
    0x258B, 0xA883,
    0x258C, 0xA884,
    0x258D, 0xA885,
    0x258E, 0xA886,
    0x258F, 0xA887,
    0x2593, 0xA888,
    0x2594, 0xA889,
    0x2595, 0xA88A,
    0x25A0, 0xA1F6,
    0x25A1, 0xA1F5,
    0x25B2, 0xA1F8,
    0x25B3, 0xA1F7,
    0x25BC, 0xA88B,
    0x25BD, 0xA88C,
    0x25C6, 0xA1F4,
    0x25C7, 0xA1F3,
    0x25CB, 0xA1F0,
    0x25CE, 0xA1F2,
    0x25CF, 0xA1F1,
    0x25E2, 0xA88D,
    0x25E3, 0xA88E,
    0x25E4, 0xA88F,
    0x25E5, 0xA890,
    0x2605, 0xA1EF,
    0x2606, 0xA1EE,
    0x2609, 0xA891,
    0x2640, 0xA1E2,
    0x2642, 0xA1E1,
    0x3000, 0xA1A1,
    0x3001, 0xA1A2,
    0x3002, 0xA1A3,
    0x3003, 0xA1A8,
    0x3005, 0xA1A9,
    0x3006, 0xA965,
    0x3007, 0xA996,
    0x3008, 0xA1B4,
    0x3009, 0xA1B5,
    0x300A, 0xA1B6,
    0x300B, 0xA1B7,
    0x300C, 0xA1B8,
    0x300D, 0xA1B9,
    0x300E, 0xA1BA,
    0x300F, 0xA1BB,
    0x3010, 0xA1BE,
    0x3011, 0xA1BF,
    0x3012, 0xA893,
    0x3013, 0xA1FE,
    0x3014, 0xA1B2,
    0x3015, 0xA1B3,
    0x3016, 0xA1BC,
    0x3017, 0xA1BD,
    0x301D, 0xA894,
    0x301E, 0xA895,
    0x3021, 0xA940,
    0x3022, 0xA941,
    0x3023, 0xA942,
    0x3024, 0xA943,
    0x3025, 0xA944,
    0x3026, 0xA945,
    0x3027, 0xA946,
    0x3028, 0xA947,
    0x3029, 0xA948,
    0x3041, 0xA4A1,
    0x3042, 0xA4A2,
    0x3043, 0xA4A3,
    0x3044, 0xA4A4,
    0x3045, 0xA4A5,
    0x3046, 0xA4A6,
    0x3047, 0xA4A7,
    0x3048, 0xA4A8,
    0x3049, 0xA4A9,
    0x304A, 0xA4AA,
    0x304B, 0xA4AB,
    0x304C, 0xA4AC,
    0x304D, 0xA4AD,
    0x304E, 0xA4AE,
    0x304F, 0xA4AF,
    0x3050, 0xA4B0,
    0x3051, 0xA4B1,
    0x3052, 0xA4B2,
    0x3053, 0xA4B3,
    0x3054, 0xA4B4,
    0x3055, 0xA4B5,
    0x3056, 0xA4B6,
    0x3057, 0xA4B7,
    0x3058, 0xA4B8,
    0x3059, 0xA4B9,
    0x305A, 0xA4BA,
    0x305B, 0xA4BB,
    0x305C, 0xA4BC,
    0x305D, 0xA4BD,
    0x305E, 0xA4BE,
    0x305F, 0xA4BF,
    0x3060, 0xA4C0,
    0x3061, 0xA4C1,
    0x3062, 0xA4C2,
    0x3063, 0xA4C3,
    0x3064, 0xA4C4,
    0x3065, 0xA4C5,
    0x3066, 0xA4C6,
    0x3067, 0xA4C7,
    0x3068, 0xA4C8,
    0x3069, 0xA4C9,
    0x306A, 0xA4CA,
    0x306B, 0xA4CB,
    0x306C, 0xA4CC,
    0x306D, 0xA4CD,
    0x306E, 0xA4CE,
    0x306F, 0xA4CF,
    0x3070, 0xA4D0,
    0x3071, 0xA4D1,
    0x3072, 0xA4D2,
    0x3073, 0xA4D3,
    0x3074, 0xA4D4,
    0x3075, 0xA4D5,
    0x3076, 0xA4D6,
    0x3077, 0xA4D7,
    0x3078, 0xA4D8,
    0x3079, 0xA4D9,
    0x307A, 0xA4DA,
    0x307B, 0xA4DB,
    0x307C, 0xA4DC,
    0x307D, 0xA4DD,
    0x307E, 0xA4DE,
    0x307F, 0xA4DF,
    0x3080, 0xA4E0,
    0x3081, 0xA4E1,
    0x3082, 0xA4E2,
    0x3083, 0xA4E3,
    0x3084, 0xA4E4,
    0x3085, 0xA4E5,
    0x3086, 0xA4E6,
    0x3087, 0xA4E7,
    0x3088, 0xA4E8,
    0x3089, 0xA4E9,
    0x308A, 0xA4EA,
    0x308B, 0xA4EB,
    0x308C, 0xA4EC,
    0x308D, 0xA4ED,
    0x308E, 0xA4EE,
    0x308F, 0xA4EF,
    0x3090, 0xA4F0,
    0x3091, 0xA4F1,
    0x3092, 0xA4F2,
    0x3093, 0xA4F3,
    0x309B, 0xA961,
    0x309C, 0xA962,
    0x309D, 0xA966,
    0x309E, 0xA967,
    0x30A1, 0xA5A1,
    0x30A2, 0xA5A2,
    0x30A3, 0xA5A3,
    0x30A4, 0xA5A4,
    0x30A5, 0xA5A5,
    0x30A6, 0xA5A6,
    0x30A7, 0xA5A7,
    0x30A8, 0xA5A8,
    0x30A9, 0xA5A9,
    0x30AA, 0xA5AA,
    0x30AB, 0xA5AB,
    0x30AC, 0xA5AC,
    0x30AD, 0xA5AD,
    0x30AE, 0xA5AE,
    0x30AF, 0xA5AF,
    0x30B0, 0xA5B0,
    0x30B1, 0xA5B1,
    0x30B2, 0xA5B2,
    0x30B3, 0xA5B3,
    0x30B4, 0xA5B4,
    0x30B5, 0xA5B5,
    0x30B6, 0xA5B6,
    0x30B7, 0xA5B7,
    0x30B8, 0xA5B8,
    0x30B9, 0xA5B9,
    0x30BA, 0xA5BA,
    0x30BB, 0xA5BB,
    0x30BC, 0xA5BC,
    0x30BD, 0xA5BD,
    0x30BE, 0xA5BE,
    0x30BF, 0xA5BF,
    0x30C0, 0xA5C0,
    0x30C1, 0xA5C1,
    0x30C2, 0xA5C2,
    0x30C3, 0xA5C3,
    0x30C4, 0xA5C4,
    0x30C5, 0xA5C5,
    0x30C6, 0xA5C6,
    0x30C7, 0xA5C7,
    0x30C8, 0xA5C8,
    0x30C9, 0xA5C9,
    0x30CA, 0xA5CA,
    0x30CB, 0xA5CB,
    0x30CC, 0xA5CC,
    0x30CD, 0xA5CD,
    0x30CE, 0xA5CE,
    0x30CF, 0xA5CF,
    0x30D0, 0xA5D0,
    0x30D1, 0xA5D1,
    0x30D2, 0xA5D2,
    0x30D3, 0xA5D3,
    0x30D4, 0xA5D4,
    0x30D5, 0xA5D5,
    0x30D6, 0xA5D6,
    0x30D7, 0xA5D7,
    0x30D8, 0xA5D8,
    0x30D9, 0xA5D9,
    0x30DA, 0xA5DA,
    0x30DB, 0xA5DB,
    0x30DC, 0xA5DC,
    0x30DD, 0xA5DD,
    0x30DE, 0xA5DE,
    0x30DF, 0xA5DF,
    0x30E0, 0xA5E0,
    0x30E1, 0xA5E1,
    0x30E2, 0xA5E2,
    0x30E3, 0xA5E3,
    0x30E4, 0xA5E4,
    0x30E5, 0xA5E5,
    0x30E6, 0xA5E6,
    0x30E7, 0xA5E7,
    0x30E8, 0xA5E8,
    0x30E9, 0xA5E9,
    0x30EA, 0xA5EA,
    0x30EB, 0xA5EB,
    0x30EC, 0xA5EC,
    0x30ED, 0xA5ED,
    0x30EE, 0xA5EE,
    0x30EF, 0xA5EF,
    0x30F0, 0xA5F0,
    0x30F1, 0xA5F1,
    0x30F2, 0xA5F2,
    0x30F3, 0xA5F3,
    0x30F4, 0xA5F4,
    0x30F5, 0xA5F5,
    0x30F6, 0xA5F6,
    0x30FC, 0xA960,
    0x30FD, 0xA963,
    0x30FE, 0xA964,
    0x3105, 0xA8C5,
    0x3106, 0xA8C6,
    0x3107, 0xA8C7,
    0x3108, 0xA8C8,
    0x3109, 0xA8C9,
    0x310A, 0xA8CA,
    0x310B, 0xA8CB,
    0x310C, 0xA8CC,
    0x310D, 0xA8CD,
    0x310E, 0xA8CE,
    0x310F, 0xA8CF,
    0x3110, 0xA8D0,
    0x3111, 0xA8D1,
    0x3112, 0xA8D2,
    0x3113, 0xA8D3,
    0x3114, 0xA8D4,
    0x3115, 0xA8D5,
    0x3116, 0xA8D6,
    0x3117, 0xA8D7,
    0x3118, 0xA8D8,
    0x3119, 0xA8D9,
    0x311A, 0xA8DA,
    0x311B, 0xA8DB,
    0x311C, 0xA8DC,
    0x311D, 0xA8DD,
    0x311E, 0xA8DE,
    0x311F, 0xA8DF,
    0x3120, 0xA8E0,
    0x3121, 0xA8E1,
    0x3122, 0xA8E2,
    0x3123, 0xA8E3,
    0x3124, 0xA8E4,
    0x3125, 0xA8E5,
    0x3126, 0xA8E6,
    0x3127, 0xA8E7,
    0x3128, 0xA8E8,
    0x3129, 0xA8E9,
    0x3220, 0xA2E5,
    0x3221, 0xA2E6,
    0x3222, 0xA2E7,
    0x3223, 0xA2E8,
    0x3224, 0xA2E9,
    0x3225, 0xA2EA,
    0x3226, 0xA2EB,
    0x3227, 0xA2EC,
    0x3228, 0xA2ED,
    0x3229, 0xA2EE,
    0x3231, 0xA95A,
    0x32A3, 0xA949,
    0x338E, 0xA94A,
    0x338F, 0xA94B,
    0x339C, 0xA94C,
    0x339D, 0xA94D,
    0x339E, 0xA94E,
    0x33A1, 0xA94F,
    0x33C4, 0xA950,
    0x33CE, 0xA951,
    0x33D1, 0xA952,
    0x33D2, 0xA953,
    0x33D5, 0xA954,
    
    // ----------------
    0xF92C, 0xFD9C,
    0xF979, 0xFD9D,
    0xF995, 0xFD9E,
    0xF9E7, 0xFD9F,
    0xF9F1, 0xFDA0,
    0xFA0C, 0xFE40,
    0xFA0D, 0xFE41,
    0xFA0E, 0xFE42,
    0xFA0F, 0xFE43,
    0xFA11, 0xFE44,
    0xFA13, 0xFE45,
    0xFA14, 0xFE46,
    0xFA18, 0xFE47,
    0xFA1F, 0xFE48,
    0xFA20, 0xFE49,
    0xFA21, 0xFE4A,
    0xFA23, 0xFE4B,
    0xFA24, 0xFE4C,
    0xFA27, 0xFE4D,
    0xFA28, 0xFE4E,
    0xFA29, 0xFE4F,
    0xFE30, 0xA955,
    0xFE31, 0xA6F2,
    0xFE33, 0xA6F4,
    0xFE34, 0xA6F5,
    0xFE35, 0xA6E0,
    0xFE36, 0xA6E1,
    0xFE37, 0xA6F0,
    0xFE38, 0xA6F1,
    0xFE39, 0xA6E2,
    0xFE3A, 0xA6E3,
    0xFE3B, 0xA6EE,
    0xFE3C, 0xA6EF,
    0xFE3D, 0xA6E6,
    0xFE3E, 0xA6E7,
    0xFE3F, 0xA6E4,
    0xFE40, 0xA6E5,
    0xFE41, 0xA6E8,
    0xFE42, 0xA6E9,
    0xFE43, 0xA6EA,
    0xFE44, 0xA6EB,
    0xFE49, 0xA968,
    0xFE4A, 0xA969,
    0xFE4B, 0xA96A,
    0xFE4C, 0xA96B,
    0xFE4D, 0xA96C,
    0xFE4E, 0xA96D,
    0xFE4F, 0xA96E,
    0xFE50, 0xA96F,
    0xFE51, 0xA970,
    0xFE52, 0xA971,
    0xFE54, 0xA972,
    0xFE55, 0xA973,
    0xFE56, 0xA974,
    0xFE57, 0xA975,
    0xFE59, 0xA976,
    0xFE5A, 0xA977,
    0xFE5B, 0xA978,
    0xFE5C, 0xA979,
    0xFE5D, 0xA97A,
    0xFE5E, 0xA97B,
    0xFE5F, 0xA97C,
    0xFE60, 0xA97D,
    0xFE61, 0xA97E,
    0xFE62, 0xA980,
    0xFE63, 0xA981,
    0xFE64, 0xA982,
    0xFE65, 0xA983,
    0xFE66, 0xA984,
    0xFE68, 0xA985,
    0xFE69, 0xA986,
    0xFE6A, 0xA987,
    0xFE6B, 0xA988,
    0xFF01, 0xA3A1,
    0xFF02, 0xA3A2,
    0xFF03, 0xA3A3,
    0xFF04, 0xA1E7,
    0xFF05, 0xA3A5,
    0xFF06, 0xA3A6,
    0xFF07, 0xA3A7,
    0xFF08, 0xA3A8,
    0xFF09, 0xA3A9,
    0xFF0A, 0xA3AA,
    0xFF0B, 0xA3AB,
    0xFF0C, 0xA3AC,
    0xFF0D, 0xA3AD,
    0xFF0E, 0xA3AE,
    0xFF0F, 0xA3AF,
    0xFF10, 0xA3B0,
    0xFF11, 0xA3B1,
    0xFF12, 0xA3B2,
    0xFF13, 0xA3B3,
    0xFF14, 0xA3B4,
    0xFF15, 0xA3B5,
    0xFF16, 0xA3B6,
    0xFF17, 0xA3B7,
    0xFF18, 0xA3B8,
    0xFF19, 0xA3B9,
    0xFF1A, 0xA3BA,
    0xFF1B, 0xA3BB,
    0xFF1C, 0xA3BC,
    0xFF1D, 0xA3BD,
    0xFF1E, 0xA3BE,
    0xFF1F, 0xA3BF,
    0xFF20, 0xA3C0,
    0xFF21, 0xA3C1,
    0xFF22, 0xA3C2,
    0xFF23, 0xA3C3,
    0xFF24, 0xA3C4,
    0xFF25, 0xA3C5,
    0xFF26, 0xA3C6,
    0xFF27, 0xA3C7,
    0xFF28, 0xA3C8,
    0xFF29, 0xA3C9,
    0xFF2A, 0xA3CA,
    0xFF2B, 0xA3CB,
    0xFF2C, 0xA3CC,
    0xFF2D, 0xA3CD,
    0xFF2E, 0xA3CE,
    0xFF2F, 0xA3CF,
    0xFF30, 0xA3D0,
    0xFF31, 0xA3D1,
    0xFF32, 0xA3D2,
    0xFF33, 0xA3D3,
    0xFF34, 0xA3D4,
    0xFF35, 0xA3D5,
    0xFF36, 0xA3D6,
    0xFF37, 0xA3D7,
    0xFF38, 0xA3D8,
    0xFF39, 0xA3D9,
    0xFF3A, 0xA3DA,
    0xFF3B, 0xA3DB,
    0xFF3C, 0xA3DC,
    0xFF3D, 0xA3DD,
    0xFF3E, 0xA3DE,
    0xFF3F, 0xA3DF,
    0xFF40, 0xA3E0,
    0xFF41, 0xA3E1,
    0xFF42, 0xA3E2,
    0xFF43, 0xA3E3,
    0xFF44, 0xA3E4,
    0xFF45, 0xA3E5,
    0xFF46, 0xA3E6,
    0xFF47, 0xA3E7,
    0xFF48, 0xA3E8,
    0xFF49, 0xA3E9,
    0xFF4A, 0xA3EA,
    0xFF4B, 0xA3EB,
    0xFF4C, 0xA3EC,
    0xFF4D, 0xA3ED,
    0xFF4E, 0xA3EE,
    0xFF4F, 0xA3EF,
    0xFF50, 0xA3F0,
    0xFF51, 0xA3F1,
    0xFF52, 0xA3F2,
    0xFF53, 0xA3F3,
    0xFF54, 0xA3F4,
    0xFF55, 0xA3F5,
    0xFF56, 0xA3F6,
    0xFF57, 0xA3F7,
    0xFF58, 0xA3F8,
    0xFF59, 0xA3F9,
    0xFF5A, 0xA3FA,
    0xFF5B, 0xA3FB,
    0xFF5C, 0xA3FC,
    0xFF5D, 0xA3FD,
    0xFF5E, 0xA1AB,
    0xFFE0, 0xA1E9,
    0xFFE1, 0xA1EA,
    0xFFE2, 0xA956,
    0xFFE3, 0xA3FE,
    0xFFE4, 0xA957,
    0xFFE5, 0xA3A4,
};
    
//各文件基址
#define CODE_UtoG_BASE (0x00000)    // unicode转GBK码表
#define CODE_GtoU_BASE (0x015800)   // GBK转unicode码表
#define FONT_12X12_BASE (0x02B000)  // 12x12GBK字库
#define FONT_16X16_BASE (0x0B7800)  // 16x16GBK字库
#define FONT_24X24_BASE (0x0172C00) // 24x24GBK字库

#if 1
/*************************************************************************************************************************
 * 函数 :  u16 GBKtoUNICODE(u16 GBKCode)
 * 功能 :  将GBK编码转换为unicode编码
 * 参数 :  GBK 
 * 返回 :  unicode
 * 依赖 :  底层读写函数
 * 作者 :  陈鹏
 * 时间 :  20120602
 * 最后修改时间 : 20120602
 * 说明 : 需要flash中的码表支持GBK码范围,高8位:0x81~0xfe;低8位:0x40~0xfe
*************************************************************************************************************************/ 
u16 GBKtoUNICODE(u16 GBKCode)
{
    u16 unicode;
    u8 buff[2];
    u16 *p;
    u8 ch,cl;

    ch = GBKCode >> 8;
    cl = GBKCode & 0x00ff;

    //计算偏移
    if(cl < 0x7f)
    unicode = (ch-0x81)*190+cl-0x40;
    if(cl > 0x80)
    unicode = (ch-0x81)*190+cl-0x41;
    unicode *= 2;

    NorFlash_ReadBuffer(buff,CODE_GtoU_BASE + unicode,2) ; //读取码表

    p = (u16 *)buff;
    return *p;
}


/*************************************************************************************************************************
 * 函数 :  u16 UNICODEtoGBK(u16 unicode)
 * 功能 :  将unicode编码转换为GBK编码
 * 参数 :  unicode
 * 返回 :  GBK 
 * 依赖 :  底层读写函数
 * 作者 :  陈鹏
 * 时间 :  20120602
 * 最后修改时间 : 20120602
 * 说明 : 需要flash中的码表支持GBK码范围,高8位:0x81~0xfe;低8位:0x40~0xfe
*************************************************************************************************************************/ 
uint16_t UNICODEtoGBK(u16 unicode)  //用二分查找算法
{
#if 1
    int i=0;
    uint8_t buf[4];
    uint16_t c1=0;
    uint16_t c2=0;
    uint32_t foffset = 0;
    
    if ((unicode <= 0x33D5)||((unicode>=0xF92C)&&(unicode<=0xFFE5))) {
        // 字符编码表 UNICODE（小于0x33D5，0xF92C~0xFFE5）通过数组检索，这些UNICODE不是连续的
        for (i=0; i<(sizeof(unicode2gbk)/4); i++) {
            if (unicode == unicode2gbk[i*2]) {
                return (uint16_t)(unicode2gbk[i*2+1]);
            }
        }
    } else if ((unicode>=0x4E00)&&(unicode<=0x9FA5)) {
        // 汉字编码表 UNICODE(0x4E00 ~ 0x9FA5) 外部flash
        foffset = (uint32_t)(unicode-0x4B33); 
    } 

#if 0
    else if (unicode == 0xF92C) {
        foffset = 21619;
    } else if (unicode == 0xF979) {
        foffset = 21620;
    } else if (unicode == 0xF995) {
        foffset = 21621;
    } else if (unicode == 0xF9E7) {
        foffset = 21622;
    } else if (unicode == 0xF9F1) {
        foffset = 21623;
    } else if ((unicode>=0xFA0C)&&(unicode<=0xFA0F)) {
        // 0xFA0C ~ 0xFA0F
        foffset = (uint32_t)(unicode-0xA594);
    } else if (unicode == 0xFA11) {
        foffset = 21628;

    } else if ((unicode>=0xFA13)&&(unicode<=0xFA14)) {
        // 0xFA13 ~ 0xFA14
        foffset = (uint32_t)(unicode-0xA596);

    } else if (unicode == 0xFA18) {
        foffset = 21631;
    } else if ((unicode>=0xFA23)&&(unicode<=0xFA24)) {
        // 0xFA1F ~ 0xFA21
        foffset = (uint32_t)(unicode-0xA59F);

    } else if ((unicode>=0xFA23)&&(unicode<=0xFA24)) {
        // 0xFA23 ~ 0xFA24
        foffset = (uint32_t)(unicode-0xA5A0);

    } else if ((unicode>=0xFA27)&&(unicode<=0xFA29)) {
        // 0xFA27 ~ 0xFA29
        foffset = (uint32_t)(unicode-0xA5A2);

    } else if ((unicode>=0xFE30)&&(unicode<=0xFE31)) {
        // 0xFE30 ~ 0xFE31
        foffset = (uint32_t)(unicode-0xA9A8);

        
    } else if ((unicode>=0xFE33)&&(unicode<=0xFE44)) {
        // 0xFE33 ~ 0xFE44
        foffset = (uint32_t)(unicode-0xA9A9);

        
    } else if ((unicode>=0xFE49)&&(unicode<=0xFE52)) {
        // 0xFE49 ~ 0xFE52
        foffset = (uint32_t)(unicode-0xA9AD);

        
    } else if ((unicode>=0xFE54)&&(unicode<=0xFE57)) {
        // 0xFE54 ~ 0xFE57
        foffset = (uint32_t)(unicode-0xA9AE);

    } else if ((unicode>=0xFE59)&&(unicode<=0xFE66)) {
        // 0xFE59 ~ 0xFE66
        foffset = (uint32_t)(unicode-0xA9AF);

    } else if ((unicode>=0xFE68)&&(unicode<=0xFE6B)) {
        // 0xFE68 ~ 0xFE6B
        foffset = (uint32_t)(unicode-0xA9B0);

    } else if ((unicode>=0xFF01)&&(unicode<=0xFF5E)) {
        // 0xFF01 ~ 0xFF5E
        foffset = (uint32_t)(unicode-0xAA45);

    } else if ((unicode>=0xFFE0)&&(unicode<=0xFFE5)) {
        // 0xFFE0 ~ 0xFFE5
        foffset = (uint32_t)(unicode-0xAAC6);
    }
#endif

    NorFlash_ReadBuffer(buf,(uint32_t)((foffset*4)+CODE_UtoG_BASE), 4);//得到GBK码
    c1 = (uint16_t)(buf[1]<<8|buf[0]);
    c2 = (uint16_t)(buf[3]<<8|buf[2]);

    log_d("%02X,%02X  %02X,%02X\n", buf[0],buf[1],buf[2],buf[3]);
    log_d("C1:%x\n", c1);
    log_d("C2:%x\n", c2);

    #if 0
    for (i=0; i<87172; i++) {
        NorFlash_ReadBuffer(buf,(uint32_t)(i+CODE_UtoG_BASE), 4);//得到GBK码
        log_d("%02X,%02X  %02X,%02X\n", buf[0],buf[1],buf[2],buf[3]);
        c1 = (uint16_t)(buf[1]<<8|buf[0]);
        if (unicode == c1) {
            c2 = (uint16_t)(buf[3]<<8|buf[2]);
            break;
        }
        i+=4;
    }
    #endif
    return c2;
#else
    uint32_t offset;
    u8 temp[2];
    u16 res;
    if(unicode<=0X9FA5) offset=unicode-0X4E00;
    else if(unicode>0X9FA5)//是标点符号
    {
        if(unicode<0XFF01||unicode>0XFF61)return 0;//没有对应编码
        offset=unicode-0XFF01+0X9FA6-0X4E00;    
    }

    log_d("offset:%d\n", offset);
    
    NorFlash_ReadBuffer(temp,(uint32_t)((offset*2)+CODE_UtoG_BASE), 2);//得到GBK码   
    res=temp[0];
    res<<=8;
    res+=temp[1];   
    return res ; //返回找到的编码
#endif
}


WCHAR ff_convert ( /* Converted code, 0 means conversion error */
    WCHAR src, /* Character code to be converted */
    UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
)
{
    WCHAR c;

    if (src < 0x80) {
        /* ASCII */
        c = src;
    } 
    else 
    {
        if (dir) 
        { /* OEMCP to unicode */

            c = GBKtoUNICODE(src);
        } 
        else 
        { /* Unicode to OEMCP */
            c = UNICODEtoGBK(src);
        }
    }

    return c;
}
#endif

void Get_HzGBKMat(unsigned char* _code, unsigned char* mat, u8 size)
{
    unsigned char qh, ql;
    unsigned char i;
    unsigned long foffset;
    
    u8 csize = (size/8 + ((size%8)?1:0)) * size;    //计算一个字符对应的点阵集合所占用的字节数
    
    qh = *_code;
    ql = *(++_code);

    log_d("qh:%x\n", qh);
    log_d("ql:%x\n", ql);

    if (qh<0x81||ql<0x40||ql==0xff||qh==0xff) //非 常用汉字
    {
        for (i=0; i<csize; i++)
        {
            *mat++ = 0x00; // 填充满格
        }
        return; // 结束访问
    }

    if (ql<0x7f) ql -= 0x40;
    else ql -= 0x41;

    qh -= 0x81;

    foffset = ((unsigned long)190*qh+ql)*csize; // 计算字库中的字节偏移量
    
    log_d("foffset:%x\n", foffset);

    switch(size)
    {
        case 12:
            // W25QXX_Read(mat, foffset + ftiinfo.f12addr, csize);
            NorFlash_ReadBuffer(mat, foffset+FONT_12X12_BASE, csize);
            break;
        case 16:
            // W25QXX_Read(mat, foffset + ftiinfo.f16addr, csize);
            NorFlash_ReadBuffer(mat, foffset+FONT_16X16_BASE, csize);
            break;
        case 24:
            // W25QXX_Read(mat, foffset + ftiinfo.f24addr, csize);
            NorFlash_ReadBuffer(mat, foffset+FONT_24X24_BASE, csize);
            break;
        default:
            break;
    }
}

void lcd_draw_gbk(char *text, int x, int y, u8 font_size, uint8_t draw_inverse, u8 draw_mode)
{
    u8 w;
    u8 h;
    char hzk[128]={0};
    char txt[3]={0};
    WCHAR gbk;
    DWORD unicode;
    
    if (E_FONT_S08X16 ==  font_size) {
        w = 8;
        h = 16;
    } else if (E_FONT_S12X12 == font_size) {
        w = 12;
        h = 12;
    } else if (E_FONT_S16X16 == font_size) {
        w = 16;
        h = 16;
    } else if (E_FONT_S16X24 == font_size) {
        w = 16;
        h = 24;
    } else if (E_FONT_S24X24 == font_size) {
        w = 24;
        h = 24;
    } else if (E_FONT_S32X32 == font_size) {
        w = 32;
        h = 32;
    }

    // UTF-8 转成UNICODE 再通过查表获取GBK编码 用于字库获取汉字
    unicode = utf8_to_unicode(text);
    gbk = ff_convert(unicode, 0);
    txt[0]=(char)((gbk>>8)&0xFF);
    txt[1]=(char)(gbk&0xFF);
    Get_HzGBKMat(txt, hzk, w);

    log_d("UTF-8  :%X\n", text);
    log_d("UNICODE:%X\n", unicode);
    log_d("GBK    :%X\n", gbk);
    
    // char txt[3]={0};
    // txt[0]=0xB9;
    // txt[1]=0xFA;
    // Get_HzGBKMat(txt, hzk, 16);
    
    lcd_draw_buf(x, y, w, h, (uint8_t*)hzk, draw_inverse, draw_mode);
}


void lcd_draw_string(char *str, int x, int y, u8 font_size, u8 wordspace, u8 align, uint8_t draw_inverse, u8 draw_mode)
{
    int i,x_offset, w,ascii_w;
    int utf8_text;
    uint8_t b1,b2,b3;
    uint8_t*_code = (uint8_t*)str;
    
    int pixels = lcd_draw_string_width_get(str, font_size, wordspace);

    if (E_FONT_S08X16 ==  font_size) {
        w = D_FONT_W_8;
        ascii_w = 8;
    } if (E_FONT_S12X12 == font_size) {
        w = D_FONT_W_12;
        ascii_w = 8;
    } if (E_FONT_S16X16 == font_size) {
        w = D_FONT_W_16;
        ascii_w = 8;
    } else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
        ascii_w = 8;
    } else if (E_FONT_S24X24 == font_size) {
        w = D_FONT_W_24;
        ascii_w = 8;
    } else if (E_FONT_S32X32 == font_size) {
        w = D_FONT_W_32;
        ascii_w = 8;
    }

    // TODO:设置排列方式
    x_offset = 0;
    if (TEXT_ALIGN_FIX == align){
        x_offset = x;
    } else if (TEXT_ALIGN_LEFT == align) {
        x_offset = 0;
    } else if (TEXT_ALIGN_RIGHT == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels);
        }
    } else if (TEXT_ALIGN_CENTER == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels)/2;
        }
    }

    while((*_code) != '\0')
    {
        u8 flag = (u8)*_code;
        if (flag <= 0x7F) {
            /* ASCII    单字节 UTF8-1  0x00-0x7F */
            lcd_draw_gbk((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += ascii_w + wordspace; 
            _code+=1;
        } else if ((flag>=0xC2)&&(flag<=0xDF)) {
            /* 汉语拼音  双字节 UTF8-2  0xC2-0xDF 0x80-0xBF */
            lcd_draw_gbk((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += ascii_w + wordspace; 
            _code+=2; 
        } else if ((flag>=0xE0)&&(flag<=0xEF)) {
            /* 汉字     三字节 UTF8-3  */
            lcd_draw_gbk((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += w + wordspace; 
            _code+=3;
        } else if ((flag>=0xF0)&&(flag<=0xF4)) {
            /*   四字节 UTF8-4  */
            log_e("unknow utf-8");
            _code+=4;
        }
    }

    if (E_DRAW_SC == draw_mode) {
        lcd_draw_update();
    }
}

#elif TCFG_FONT_LIBRARY_TYPE == 1 // UNICODE编码字库

#define FONT_12X12_BASE (0x000000)  // unicode 12x12 字库
#define FONT_16X16_BASE (0x180000)  // unicode 16x16 字库
#define FONT_24X24_BASE (0x380000) // unicode 24x24 字库

void Get_HzUnicodeMat(unsigned char* _code, unsigned char* mat, u8 font_size)
{
    uint8_t size=8;
    uint8_t qh, ql;
    uint8_t i;
    uint8_t csize;
    uint32_t foffset;
    uint32_t unicode;

    if (E_FONT_S08X16 ==  font_size) {
        size = D_FONT_W_8;
    } else if (E_FONT_S12X12 == font_size) {
        size = D_FONT_W_12;
    } else if (E_FONT_S16X16 == font_size) {
        size = D_FONT_W_16;
    } else if (E_FONT_S16X24 == font_size) {
        size = D_FONT_W_16;
    } else if (E_FONT_S24X24 == font_size) {
        size = D_FONT_W_24;
    } else if (E_FONT_S32X32 == font_size) {
        size = D_FONT_W_32;
    }

    unicode = utf8_to_unicode(_code);
   
    csize = (size/8 + ((size%8)?1:0)) * size;    //计算一个字符对应的点阵集合所占用的字节数

    foffset = (unsigned long)((unsigned long)unicode*(unsigned long)csize);

    // log_d("utf-8:%x\n", _code);
    // log_d("unicode:%x\n", unicode);
    // log_d("csize:%d\n", csize);
    // log_d("foffset:%lu\n", foffset);

    switch (font_size)
    {
        case E_FONT_S12X12:
            NorFlash_ReadBuffer(mat, FONT_12X12_BASE + foffset, csize);
            break;
        case E_FONT_S16X16:
            NorFlash_ReadBuffer(mat, FONT_16X16_BASE + foffset, csize);
            break;
        case E_FONT_S24X24:
            NorFlash_ReadBuffer(mat, FONT_24X24_BASE + foffset, csize);
            break;       
        default:
            break;
    }
}

void lcd_draw_unicode(char *text, int x, int y, u8 font_size, uint8_t draw_inverse, u8 draw_mode)
{
    u8 w;
    u8 h;
    char hzk[128]={0};
       
    if (E_FONT_S08X16 ==  font_size) {
        w = 8;
        h = 16;
    } else if (E_FONT_S12X12 == font_size) {
        w = 12;
        h = 12;
    } else if (E_FONT_S16X16 == font_size) {
        w = 16;
        h = 16;
    } else if (E_FONT_S16X24 == font_size) {
        w = 16;
        h = 24;
    } else if (E_FONT_S24X24 == font_size) {
        w = 24;
        h = 24;
    } else if (E_FONT_S32X32 == font_size) {
        w = 32;
        h = 32;
    }

    // DWORD	uni = utf8_to_unicode(text);
    // WCHAR gbk = ff_uni2oem(uni, FF_CODE_PAGE);
    // Get_HzGBKMat(gbk, hzk, 16);

    // char txt[3]={0};
    // txt[0]=0xB9;
    // txt[1]=0xFA;
    // Get_HzGBKMat(txt, hzk, 16);

    
    Get_HzUnicodeMat(text, hzk, font_size);

    lcd_draw_buf(x, y, w, h, (uint8_t*)hzk, draw_inverse, draw_mode);
}


void lcd_draw_string(char *str, int x, int y, u8 font_size, u8 wordspace, u8 align, uint8_t draw_inverse, u8 draw_mode)
{
    int i,x_offset, w,ascii_w;
    int utf8_text;
    uint8_t b1,b2,b3;
    uint8_t*_code = (uint8_t*)str;
    
    int pixels = lcd_draw_string_width_get(str, font_size, wordspace);

    if (E_FONT_S08X16 ==  font_size) {
        w = D_FONT_W_8;
        ascii_w = 8;
    } else if (E_FONT_S12X12 == font_size) {
        w = D_FONT_W_12;
        ascii_w = 6;
    } else if (E_FONT_S16X16 == font_size) {
        w = D_FONT_W_16;
        ascii_w = 8;
    } else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
        ascii_w = 8;
    } else if (E_FONT_S24X24 == font_size) {
        w = D_FONT_W_24;
        ascii_w = 12;
    } else if (E_FONT_S32X32 == font_size) {
        w = D_FONT_W_32;
        ascii_w = 16;
    }

    // TODO:设置排列方式
    x_offset = 0;
    if (TEXT_ALIGN_FIX == align){
        x_offset = x;
    } else if (TEXT_ALIGN_LEFT == align) {
        x_offset = 0;
    } else if (TEXT_ALIGN_RIGHT == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels);
        }
    } else if (TEXT_ALIGN_CENTER == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels)/2;
        }
    }

    while((*_code) != '\0')
    {
        u8 flag = (u8)*_code;
        if (flag <= 0x7F) {
            /* ASCII    单字节 UTF8-1  0x00-0x7F */
            lcd_draw_unicode((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += ascii_w + wordspace; 
            _code+=1;
        } else if ((flag>=0xC2)&&(flag<=0xDF)) {
            /* 汉语拼音  双字节 UTF8-2  0xC2-0xDF 0x80-0xBF */
            lcd_draw_unicode((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += ascii_w + wordspace; 
            _code+=2; 
        } else if ((flag>=0xE0)&&(flag<=0xEF)) {
            /* 汉字     三字节 UTF8-3  */
            lcd_draw_unicode((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += w + wordspace; 
            _code+=3;
        } else if ((flag>=0xF0)&&(flag<=0xF4)) {
            /*   四字节 UTF8-4  */
            log_e("unknow utf-8");
            _code+=4;
        }
    }

    if (E_DRAW_SC == draw_mode) {
        lcd_draw_update();
    }
}
#endif

#else

/**
 *  编码格式        第一字节范围        第二字节范围        第三字节范围        第四字节范围
 *  UTF8-1          0x00-0x7F

    UTF8-2          0xC2-0xDF          0x80-0xBF

    UTF8-3          0xE0               0xA0-0xBF            0x80-0xBF
                    0xE1-0xEC          0x80-0xBF            0x80-0xBF
                    0xED               0x80-0x9F            0x80-0xBF
                    0xEE-0xEF          0x80-0xBF            0x80-0xBF

    UTF8-4          0xF0               0x90-0xBF            0x80-0xBF          0x80-0xBF
                    0xF1-0xF3          0x80-0xBF            0x80-0xBF          0x80-0xBF
                    0xF4               0x80-0x8F            0x80-0xBF          0x80-0xBF 
 * 
*/

/**
 * @brief   显示ASCII字符
 * 
*/
void lcd_draw_ascii(char *text, int x, int y, u8 font_size, uint8_t draw_inverse, u8 draw_mode)
{
    uint8_t w,h;
    uint16_t i=0;
    uint16_t font_total=0;
    void* font_data;

#if TCFG_FONT_SIZE_ASCII_8X16_ENABLE
    if (E_FONT_S08X16 == font_size) {
        w = D_FONT_W_8;
        h = D_FONT_H_16;
        font_total = sizeof(Font_Data_8x16_ASCII)/sizeof(struct font_ascii_8x16_t);
        font_data = (struct font_ascii_8x16_t*)&Font_Data_8x16_ASCII;

        for (i=0; i<font_total; i++) {
            char _code = (char)((struct font_ascii_8x16_t*)font_data)[i].txt[0];
            // log_debug("ascii text:%x, _code:%x", text[0], _code);

            if (text[0] == _code) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_ascii_8x16_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        }
    }
#endif
#if TCFG_FONT_SIZE_ASCII_16X24_ENABLE
    else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
        h = D_FONT_H_24;
        font_total = sizeof(Font_Data_16x24_ASCII)/sizeof(struct font_ascii_16x24_t);
        font_data = (struct font_ascii_16x24_t*)&Font_Data_16x24_ASCII;

        for (i=0; i<font_total; i++) {
            char _code = (char)((struct font_ascii_16x24_t*)font_data)[i].txt[0];
            // log_debug("ascii text:%x, _code:%x", text[0], _code);

            if (text[0] == _code) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_ascii_16x24_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        }
    }
#endif    
}

/**
 * @brief   显示汉语拼音
*/
void lcd_draw_pinyin(char *text, int x, int y, u8 font_size, uint8_t draw_inverse, u8 draw_mode)
{
    u8 w,h;
    u16 i;
    u16 font_total=0;
    void* font_data;

    int utf8_text;
    int utf8_font;
    uint8_t b1,b2,b3;
	uint8_t* _code = (uint8_t*)text;
	
#if TCFG_FONT_SIZE_ASCII_8X16_ENABLE
    if (E_FONT_S08X16 == font_size) {
        w = D_FONT_W_8;
        h = D_FONT_H_16;
        font_total = sizeof(Font_Data_8x16_ASCII)/sizeof(struct font_ascii_8x16_t);
        font_data = (struct font_ascii_8x16_t*)&Font_Data_8x16_ASCII;
        
        b1 = (uint8_t)*_code++;
        b2 = (uint8_t)*_code;
        utf8_text = ((b1<<8)|(b2));    

        for (i=0; i<font_total; i++) {
            _code = (uint8_t*)((struct font_ascii_8x16_t*)font_data)[i].txt;
            b1 = (uint8_t)*_code++;
            b2 = (uint8_t)*_code;
            utf8_font = ((b1<<8)|(b2));
            // log_d("index:%d, utf8_text:0x%x utf8_font:0x%x", i, utf8_text, utf8_font);

            if (utf8_font == utf8_text) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_ascii_8x16_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        }
    }
#endif
#if TCFG_FONT_SIZE_ASCII_16X24_ENABLE
    else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
        h = D_FONT_H_24;
        font_total = sizeof(Font_Data_16x24_ASCII)/sizeof(struct font_ascii_16x24_t);
        font_data = (struct font_ascii_16x24_t*)&Font_Data_16x24_ASCII;

        b1 = (uint8_t)*_code++;
        b2 = (uint8_t)*_code;
        utf8_text = ((b1<<8)|(b2));    

        for (i=0; i<font_total; i++) {
            _code = (uint8_t*)((struct font_ascii_16x24_t*)font_data)[i].txt;
            b1 = (uint8_t)*_code++;
            b2 = (uint8_t)*_code;
            utf8_font = ((b1<<8)|(b2));
            // log_d("index:%d, utf8_text:0x%x utf8_font:0x%x", i, utf8_text, utf8_font);

            if (utf8_font == utf8_text) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_ascii_16x24_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        }
    }
#endif
}

/**
 * @brief   显示汉字字符
 * @param   text:文字字符
 * @param   x: 显示位置x坐标
 * @param   y: 显示位置y坐标
 * @param   font_size:  字体大小
 * @param   draw_inverse: 是否反色显示
 * @param   draw_mode：刷新模式，刷新到GRAM或SCREEN
*/
void lcd_draw_chinese(char *text, int x, int y, u8 font_size, uint8_t draw_inverse, u8 draw_mode)
{
    u32 i;
    u32 font_total=0;
    u8 w;
    u8 h;
    int utf8_text;
    int utf8_font;
    uint8_t b1,b2,b3;
    void* font_data;

    uint8_t* _code = (uint8_t*)text;
    b1 = (uint8_t)*_code++;
    b2 = (uint8_t)*_code++;
    b3 = (uint8_t)*_code;
    utf8_text = ((b1<<16)|(b2<<8)|(b3));

    log_d("utf8_text:0x%x", utf8_text);

#if TCFG_FONT_SIZE_HZK_16X16_ENABLE
    if (E_FONT_S16X16 == font_size) {
        w = D_FONT_W_16;
        h = D_FONT_H_16;
        font_total = sizeof(Font_Data_16x16_HZK)/sizeof(struct font_hzk_16x16_t);
        font_data = (struct font_hzk_16x16_t*)&Font_Data_16x16_HZK;

    } else 
#endif
#if TCFG_FONT_SIZE_HZK_16X24_ENABLE
    if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
        h = D_FONT_H_24;
        font_total = sizeof(Font_Data_16x24_HZK)/sizeof(struct font_hzk_16x24_t);
        font_data = (struct font_hzk_16x24_t*)&Font_Data_16x24_HZK;
    } else
#endif
#if TCFG_FONT_SIZE_24X24_ENABLE
    if (E_FONT_S24X24 == font_size) {
        w = D_FONT_W_24;
        h = D_FONT_H_24;
        font_total = sizeof(Font_Data_24x24_HZK)/sizeof(struct font_data_24x24_t);
        font_data = (struct font_data_24x24_t*)&Font_Data_24x24_HZK;

    } else 
#endif
#if TCFG_FONT_SIZE_32X32_ENABLE
    if (E_FONT_S32X32 == font_size) {
        w = D_FONT_W_32;
        h = D_FONT_H_32;
        font_total = sizeof(Font_Data_32x32_HZK)/sizeof(struct font_data_32x32_t);
        font_data = (struct font_data_32x32_t*)&Font_Data_32x32_HZK;
    }
#else 
    {

    }
#endif

    // log_d("chiness font_total:%d", font_total);

    for (i=0; i<font_total; i++)
    {        
    #if TCFG_FONT_SIZE_HZK_16X16_ENABLE
        if (E_FONT_S16X16 == font_size) {
            _code = (uint8_t*)(((struct font_hzk_16x16_t*)font_data)[i].txt);
            b1 = (uint8_t)*_code++;
            b2 = (uint8_t)*_code++;
            b3 = (uint8_t)*_code;
            utf8_font = ((b1<<16)|(b2<<8)|(b3));
            // log_d("index:%d, utf8_font:0x%x", i, utf8_font);

            if (utf8_font == utf8_text) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_hzk_16x16_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        } else 
    #endif
    #if TCFG_FONT_SIZE_16X24_ENABLE
        if (E_FONT_S16X24 == font_size) {
            _code = (uint8_t*)((struct font_data_16x24_t*)font_data)[i].txt;
            b1 = (uint8_t)*_code++;
            b2 = (uint8_t)*_code++;
            b3 = (uint8_t)*_code;
            utf8_font = ((b1<<16)|(b2<<8)|(b3));
            // log_d("index:%d, utf8_font:0x%x", i, utf8_font);

            if (utf8_font == utf8_text) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_data_16x24_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        } else
    #endif
    #if TCFG_FONT_SIZE_24X24_ENABLE
        if (E_FONT_S24X24 == font_size) {
            _code = (uint8_t*)((struct font_data_24x24_t*)font_data)[i].txt;
            b1 = (uint8_t)*_code++;
            b2 = (uint8_t)*_code++;
            b3 = (uint8_t)*_code;
            utf8_font = ((b1<<16)|(b2<<8)|(b3));
            // log_d("index:%d, utf8_font:0x%x", i, utf8_font);

            if (utf8_font == utf8_text) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_data_24x24_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        } else 
    #endif
    #if TCFG_FONT_SIZE_32X32_ENABLE
        if (E_FONT_S32X32 == font_size) {
            _code = (uint8_t*)((struct font_data_32x32_t*)font_data)[i].txt;
            b1 = (uint8_t)*_code++;
            b2 = (uint8_t)*_code++;
            b3 = (uint8_t)*_code;
            utf8_font = ((b1<<16)|(b2<<8)|(b3));
            // log_d("index:%d, utf8_font:0x%x", i, utf8_font);

            if (utf8_font == utf8_text) {
                lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_data_32x32_t*)font_data)[i].dat, draw_inverse, draw_mode);
                return;
            }
        }
    #else 
        {

        }
    #endif

    #if 0
        _code = (uint8_t*)((struct font_data_32x32_t*)font_data)[i].txt;
        b1 = (uint8_t)*_code++;
        b2 = (uint8_t)*_code++;
        b3 = (uint8_t)*_code;
        utf8_font = ((b1<<16)|(b2<<8)|(b3));
        // log_d("index:%d, utf8_font:0x%x", i, utf8_font);

        if (utf8_font == utf8_text) {
            lcd_draw_buf(x, y, w, h, (uint8_t*)((struct font_data_32x32_t*)font_data)[i].dat, draw_inverse, draw_mode);
            return;
        }
    #endif
    }

    log_d("can not find text in font!\n");
}



/**
 * @brief   显示字符串
 * @param   str:文字字符串
 * @param   x: 显示位置x坐标
 * @param   y: 显示位置y坐标
 * @param   font_size:  字体大小
 * @param   wordspace:  字间隔
 * @param   align: 对齐方式
 * @param   draw_inverse: 是否反色显示
 * @param   draw_mode：刷新模式，刷新到GRAM或SCREEN
*/
#if 1
void lcd_draw_string(char *str, int x, int y, u8 font_size, u8 wordspace, u8 align, uint8_t draw_inverse, u8 draw_mode)
{
    int i,x_offset, w;
    int utf8_text;
    uint8_t b1,b2,b3;
    uint8_t*_code = (uint8_t*)str;
    
    int pixels = lcd_draw_string_width_get(str, font_size, wordspace);

    if (E_FONT_S08X16 ==  font_size) {
        w = D_FONT_W_8;
    } else if (E_FONT_S16X16 == font_size) {
        w = D_FONT_W_16;
    } else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
    } else if (E_FONT_S24X24 == font_size) {
        w = D_FONT_W_24;
    } else if (E_FONT_S32X32 == font_size) {
        w = D_FONT_W_32;
    }

    // TODO:设置排列方式
    x_offset = 0;
    if (TEXT_ALIGN_FIX == align){
        x_offset = x;
    } else if (TEXT_ALIGN_LEFT == align) {
        x_offset = 0;
    } else if (TEXT_ALIGN_RIGHT == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels);
        }
    } else if (TEXT_ALIGN_CENTER == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels)/2;
        }
    }

    while((*_code) != '\0')
    {
        u8 flag = (u8)*_code;
        if (flag <= 0x7F) {
            /* ASCII    单字节 UTF8-1  0x00-0x7F */
            lcd_draw_ascii((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += w + wordspace; 
            _code+=1;
        } else if ((flag>=0xC2)&&(flag<=0xDF)) {
            /* 汉语拼音  双字节 UTF8-2  0xC2-0xDF 0x80-0xBF */
            lcd_draw_pinyin((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += w + wordspace; 
            _code+=2; 
        } else if ((flag>=0xE0)&&(flag<=0xEF)) {
            /* 汉字     三字节 UTF8-3  */
            lcd_draw_chinese((char*)_code, x_offset, y, font_size, draw_inverse, draw_mode);
            x_offset += w + wordspace; 
            _code+=3;
        } else if ((flag>=0xF0)&&(flag<=0xF4)) {
            /*   四字节 UTF8-4  */
            log_e("unknow utf-8");
            _code+=4;
        }
    }

    if (E_DRAW_SC == draw_mode) {
        lcd_draw_update();
    }
}

#else


/**
 * @brief   显示字符
 * @param   text:文字字符
 * @param   x: 显示位置x坐标
 * @param   y: 显示位置y坐标
 * @param   font_size:  字体大小
 * @param   draw_inverse: 是否反色显示
 * @param   draw_mode：刷新模式，刷新到GRAM或SCREEN
*/
void lcd_draw_text(char *text, int x, int y, u8 font_size, uint8_t draw_inverse, u8 draw_mode)
{
    u8 flag = text[0];
    if (flag <= 0x7F) {
        /* ASCII    单字节 UTF8-1  0x00-0x7F */
        lcd_draw_ascii(text, x, y, font_size, draw_inverse, draw_mode);
           
    } else if ((flag>=0xC2)&&(flag<=0xDF)) {
        /* 汉语拼音  双字节 UTF8-2  0xC2-0xDF 0x80-0xBF */
        lcd_draw_pinyin(text, x, y, font_size, draw_inverse, draw_mode);

    } else if ((flag>=0xE0)&&(flag<=0xEF)) {
        /* 汉字     三字节 UTF8-3  */
        lcd_draw_chinese(text, x, y, font_size, draw_inverse, draw_mode);

    } else if ((flag>=0xF0)&&(flag<=0xF4)) {
        /*   四字节 UTF8-4  */
        log_e("unknow utf-8");
    }
}

void lcd_draw_str(char *str, int x, int y, u8 font_size, u8 wordspace, u8 align, uint8_t draw_inverse, u8 draw_mode)
{
    int i,x_offset, w;
    int utf8_text;
    uint8_t b1,b2,b3;
    uint8_t*_code = (uint8_t*)str;

    int str_bytes = strlen(str);
    // log_d("str_bytes:%d", str_bytes);
    
    int pixels = draw_string_width_pixels(str, font_size, wordspace);

    if (E_FONT_S16X16 == font_size) {
        w = D_FONT_W_16;
    } else if (E_FONT_S16X24 == font_size) {
        w = D_FONT_W_16;
    } else if (E_FONT_S24X24 == font_size) {
        w = D_FONT_W_24;
    } else if (E_FONT_S32X32 == font_size) {
        w = D_FONT_W_32;
    }

    // TODO:设置排列方式
    x_offset = 0;
    if (TEXT_ALIGN_FIX == align){
        x_offset = x;
    } else if (TEXT_ALIGN_LEFT == align) {
        x_offset = 0;
    } else if (TEXT_ALIGN_RIGHT == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels);
        }
    } else if (TEXT_ALIGN_CENTER == align) {        
        if (pixels < LCD_WIDTH) {
            x_offset = (LCD_WIDTH - pixels)/2;
        }
    }

    for (i=0; i<str_bytes; i+=3)
    {
        b1 = (uint8_t)*_code++;
        b2 = (uint8_t)*_code++;
        b3 = (uint8_t)*_code++;

        utf8_text = ((b3<<16)|(b2<<8)|(b1));    // CPU 大端模式
        // utf8_text = ((b1<<16)|(b2<<8)|(b3)); // CPU 小端模式

        // log_d("i:%d, x_offset:%d, utf8_text:0x%x", i, x_offset, utf8_text);
        lcd_draw_text((char*)&utf8_text,  x_offset,  y, font_size, draw_inverse, E_DRAW_FB);
        x_offset += w + wordspace;  // 
    }


    if (E_DRAW_SC == draw_mode) {
        lcd_draw_update();
    }
}
#endif
#endif
#endif




